package com.cloud.weichat;

import java.net.InetAddress;
import java.util.ResourceBundle;

/**
 * @author zhangli
 *	配置文件读取类
 */
public class PARAMUTIL {

	static ResourceBundle MASTERAGENTINFO = null;

	static {
		try {
			MASTERAGENTINFO = ResourceBundle.getBundle("weichat");
		} catch (Exception e) {
			System.out.println("Bundle MASTERAGENT.properties error.");
			e.printStackTrace();
		}
	}

	public static int getInt(String paramname) {
		int paramvalue = 0;
		try {
			String cParamvalue = MASTERAGENTINFO.getString(paramname).trim();
			paramvalue = Integer.parseInt(cParamvalue);
		} catch (Exception e) {
			System.out.println("get param " + paramname + "error.");
			e.printStackTrace();
		}
		return paramvalue;
	}

	public static String getString(String paramname) {
		if (paramname != null && paramname.equals("HOSTADDR")) {
			return getHOSTADDR();
		}
		String paramvalue = MASTERAGENTINFO.getString(paramname).trim();
		return paramvalue;

	}

	public static String getHOSTADDR() {
		String paramvalue = "127.0.0.1";
		try {
			paramvalue = InetAddress.getLocalHost().toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return paramvalue;
	}

	public static String getString(String baseName, String key) {

		ResourceBundle logFileInfo = ResourceBundle.getBundle(baseName);
		String value = logFileInfo.getString(key).trim();
		return value;
	}

	public static int getInt(String baseName, String key) {

		ResourceBundle logFileInfo = ResourceBundle.getBundle(baseName);
		String value = logFileInfo.getString(key).trim();
		return Integer.parseInt(value);
	}
}
